package com.xinchuang.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinchuang.entity.EdtionNotice;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EdtionNoticeMapper extends BaseMapper<EdtionNotice> {

    @Select(value = "SELECT edition FROM edtion_notice WHERE red_id = #{id} ORDER BY create_time DESC LIMIT 1")
    String getEditionValue(@Param("id") String id);

    @Select(value = {
            "SELECT e.edition,e.key_name,e.key_value,e.base_value,e.update_value,ua.`name` AS person,e.create_time FROM edtion_notice e LEFT JOIN user_api ua ON e.person = ua.user_id",
            "WHERE e.red_id = #{id}",
            "ORDER BY e.edition DESC"
    })
    IPage<EdtionNotice> getEdition(Page page, @Param("id") String id);

    @Select(value = {
            "SELECT e.edition,e.key_name,e.key_value,e.base_value,e.update_value,ua.`name` AS person,e.create_time FROM edtion_notice e LEFT JOIN user_api ua ON e.person = ua.user_id",
            "WHERE e.red_id = #{id} AND edition = #{edition}",
    })
    List<EdtionNotice> getEditionList(@Param("edition") String edition, @Param("id") String id);


    @Select(value = {
            "SELECT e.edition,e.key_name,e.key_value,e.base_value,e.update_value,ua.`name` AS person,e.create_time FROM edtion_notice e LEFT JOIN user_api ua ON e.person = ua.user_id",
            "WHERE e.red_id = #{id}",
    })
    List<EdtionNotice> getEditionList(@Param("id") String id);

}
